Skip to content

fix(car): a charger-linked Octopus Intelligent target adds to the SoC at plug-in (#3034) - #5822

Merged
springfall2008 merged 4 commits into
mainfrom
fix/octopus-charger-target-to-add-3034
Oct 29, 2026
Merged

springfall2008 merged 4 commits into
mainfrom
fix/octopus-charger-target-to-add-3034

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Opened by Claude on behalf of @chalfontchubby.

Fixes #3034. Also addresses #3060, which has the same root cause.

Problem

When Octopus Intelligent is linked to the charger rather than the car, Octopus's charge target means "add X%", not "charge to X%". Predbat read octopus_charge_limit as a SoC to reach. So a car with a real SoC sensor was treated as already charged, and its slots were dropped. The #3034 log shows exactly this: 39% with "add 40%", and the car is "already charged" at 43%.

Change

  • Detecting which device is linked: the new shared helper utils.intelligent_device_is_charger() checks, in order:

    1. is_charger on the dispatch sensor, from Predbat's own Octopus and Kraken components.
    2. device_type (ELECTRIC_VEHICLE_CHARGERS / ELECTRIC_VEHICLES), on the car's octopus_charge_limit entity or the dispatch sensor. It's for feat: Indicate whether the intelligent charge target is a state of charge or a percentage to add BottlecapDave/HomeAssistant-OctopusEnergy#1917, which is still open, so today it's only read if present.
    3. Failing both, which size the Octopus Energy integration's dispatch sensor fills in. It sets only charge_point_power_in_kw for a charger, and only vehicle_battery_size_in_kwh for a car. I checked this against the integration's source.

    If none of these says, the target is read as a SoC to reach, as before.

  • Charger-linked limit: the SoC at plug-in plus the target, still capped by car_charging_limit.

    • The plug-in SoC is captured when the car is plugged in and held until it's unplugged. So a stale low reading while it charges can't drag the limit down, and a reading of 0 (an unreadable sensor) never replaces it.
    • "Plugged in" comes from car_charging_plugged where it's set. Otherwise it comes from car_charging_planned, the car charging now, or planned dispatches (unless octopus_intelligent_ignore_unplugged).
  • Ohme: when Ohme has claimed car 0's charge limit, octopus_charge_limit is Ohme's own SoC target and is never treated as a percentage to add.

  • compare.py re-runs (save=False) use the live fetch's plug-in SoC without recording one.

The helper is ready for charger control to use, but deliberately isn't wired in here. Telling the device apart for Octopus Energy integration users changes what an explicit charger control setting does, which needs deciding alongside #5807's veto. See #5808.

Known limits

  • The plug-in SoC isn't saved. After a restart partway through a charge, it starts again from the SoC at that moment, so the limit can only come out higher than Octopus's target (Predbat keeps the slots), not lower.
  • The percentage is taken of Predbat's battery size for the car. A charger-linked device carries no battery size of its own, so Octopus's idea of the battery may differ.
  • Without a plug sensor, planned dispatches count as "plugged in". If Octopus keeps listing them after an unplug, the plug-in SoC isn't refreshed until they stop.

Tests

./run_all --test octopus_charge_target: 15 cases covering:

  • detection order and each source, including device_type on the charge target and is_charger as a string
  • the Predbat thinks car is charged if car soc > Octopus target charge to add #3034 numbers
  • holding the base through charging, a 0 reading and a stale low reading
  • unplug and replug, the car's own limit cap, compare.py re-runs
  • plugged-in from charging now, planned dispatches, and the plug sensor
  • the Ohme claim
  • a car-linked or unknown target staying unchanged

They fail on main. ./run_all --quick passes, and so does pre-commit. A cold review and /code-review high were run, and their findings are fixed in the last commit.

🤖 Generated with Claude Code

chalfontchubby and others added 3 commits October 28, 2026 19:53
… at plug-in (#3034)

With Octopus linked to the charger rather than the car, Octopus cannot see the
car's SoC, so its charge target is a percentage to add rather than a SoC to
reach. Predbat read it as a SoC ceiling: a car plugged in at 39% with "add 40%"
was taken as already charged as soon as the charge Octopus does at plug-in took
it past 40%, and its Intelligent slots were then ignored.

Which device is linked comes from the dispatch sensor: is_charger from
Predbat's own Octopus and Kraken components, device_type from the HA Octopus
Energy integration (proposed upstream), and otherwise from the integration
filling in only the charge point's power for a charger and only the battery
size for a car. When none of these says, the target is read as before.

The plug-in SoC is the lowest SoC seen while plugged in, held in memory. The
limit can only come out higher than before, never lower, and users with no
car SoC sensor (SoC 0) are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elper; read device_type from the charge target

The #3034 detection - is_charger, then device_type, then which size the
Octopus Energy integration's dispatch sensor fills in - moves out of
Fetch into utils.intelligent_device_is_charger(), so charger control can
use the same rule later rather than a copy.

device_type is now also read from the car's octopus_charge_limit entity
when that is an entity: BottlecapDave/HomeAssistant-OctopusEnergy#1917
puts it on the intelligent charge target, not on the dispatch sensor. A
target set as a plain number has no entity, so the dispatch sensor alone
decides, as before. is_charger as a string ("true"/"false") is read too.

Charger control is deliberately not switched to it here: detecting the
device for Octopus Energy integration users changes what an explicit
charger control setting does, which needs deciding with #5807's veto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… sensor, and leave an Ohme target alone

Review follow-ups for #3034:

- The base was the lowest SoC seen while plugged in, so one stale low
  reading latched it and the "add X%" limit with it - dropping the car's
  slots, the #3034 symptom. It is now captured when the car is plugged in
  and held until it is unplugged.
- Plugged in is read from car_charging_plugged where it is set, since
  car_charging_planned can turn off at the end of a charge with the car
  still plugged in. Without a plug sensor the old rule stands.
- When Ohme has claimed car 0's charge limit, octopus_charge_limit is
  Ohme's own SoC target, so it is never treated as a percentage to add.
- is_charger strings and numbers are read as the charger control reads
  them.
- The "linked to the charger" line is logged when it changes, not every
  cycle.
- Docs: device_type on the charge target is read should the integration
  add it, rather than claimed as something it does today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the BOT_REVIEW Trigger an autotriage label Oct 28, 2026

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated comment from the triage bot.

Reviewed 72280ee (fix(car): a charger-linked Octopus Intelligent target adds to the SoC at plug-in, #3034). The core is sound: is_charger really is published on the dispatch sensor by Predbat's own Octopus and Kraken components (octopus.py:2845, octopus.py:2948, kraken.py:1471), so the shared helper's first check keys off real data; the plug-in base holds through charging, a 0 reading and a stale-low reading (tests 7/13/14); a plug sensor outranks car_charging_planned where it is set (test 14); compare.py re-runs (save=False) reuse the live base without recording one (test 6); an Ohme-claimed target stays a SoC to reach (test 15); and the #3034 numbers resolve correctly - 39% + "add 40%" → 79% limit, so the car_charging_soc >= car_charging_limit drop at execute.py:944 no longer fires, and #3060's IOG-charger "add 22%" reads the same way. Detection falls back to the old SoC-to-reach reading when nothing says, which is the conservative default. 1 low finding, posted inline; none in the body.

Comment thread apps/predbat/fetch.py Resolved
@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Oct 28, 2026
While the car is unplugged the base follows the live SoC, so the
"adds X kWh to the Y kWh the car had when plugged in" line re-fired on
every cycle of a drive with a number that was not a plug-in SoC. Leave
the base out of the change key while unplugged and log only when plugged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008
springfall2008 merged commit 5811b40 into main Oct 29, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/octopus-charger-target-to-add-3034 branch October 29, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Predbat thinks car is charged if car soc > Octopus target charge to add

2 participants